// 定义一个user的状态管理
export const userState = defineStore('user', {
    // 定义状态
    state: () => {
        return {
            uuid: "",
            username: "",
            account: "",
            avatar: "",
            token: "",
            role: ""
        }
    },

    // 修改状态
    actions: {
        setLoginUserInfo(user) {
            this.uuid = user.uuid
            this.username = user.username
            this.account = user.account
            this.avatar = user.avatar
            this.role = user.role
            this.token = user.token
        }
    },

    // 状态数据获取和加工，和computed一样，定义的是方法使用的时候是属性
    getters: {
        isLogin() {
            return this.uuid != ""
        }
    },

    //persist定义要做判断，因为localStorage是客户端参数，所以需要加process.client
    persist: process.client && {
        storage: localStorage, // sessionStorage/localStorage
        key: 'kva-cc-userlogin', // storage的key
    }
})
